addLoadEvent(function () {
	jQuery('input.trex_delete').click(function () {
		if (!confirm("Are you sure you want to delete this entry?")) return false;
		document.location = this.getAttribute('data-action');
	});

	jQuery('input.trex_save, input.trex_add').click(function () {
		var form = document.getElementById('trex_form');
		form.action = this.getAttribute('data-action');
		form.elements['trex_date'].value = jQuery('input[name=trex_date]', this.parentNode.parentNode).attr('value');
		form.elements['trex_amount'].value = jQuery('input[name=trex_amount]', this.parentNode.parentNode).attr('value');
		form.elements['trex_currency'].value = jQuery('input[name=trex_currency]', this.parentNode.parentNode).attr('value');
		form.elements['trex_income'].value = jQuery('input[name=trex_income]', this.parentNode.parentNode).attr('checked') ? 'yes' : '';
		form.elements['trex_name'].value = jQuery('input[name=trex_name]', this.parentNode.parentNode).attr('value');
		form.elements['trex_type'].value = jQuery('input[name=trex_type]', this.parentNode.parentNode).attr('value');
		form.elements['sure'].value = 'yep';
		form.submit();
	});

	jQuery('input[name=trex_date], input[name=trex_amount], input[name=trex_currency], input[name=trex_name], input[name=trex_type]').keypress(function (event) {
		if (event.which == 13) {
			jQuery('input.trex_save, input.trex_add', this.parentNode.parentNode).trigger('click');
		}
		return true;
	});
});